package com.fmdj.odr;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class HelloScheduler {
    public static void main(String[] args)throws Exception {

        /**
         * jobDetail: 用来绑定Job,并且在job执行的时候携带一些执行信息
         */
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class)
                .withIdentity("myJob", "group1").build();


        /**
         * Trigger: 用来触发job执行,定义什么时候去执行
         * 第一次执行,重复执行,执行几次
         * withIdentity():指定触发器的名字和所属的组
         * startNow():定义现在开始执行
         * .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3).repeatForever()):
         *   每隔3秒执行一次,不间断重复执行
         */
        SimpleTrigger simpleTrigger = TriggerBuilder.newTrigger().withIdentity("myTrigger", "group1")
                .withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(3).repeatForever()).build();

        Scheduler scheduler = new StdSchedulerFactory().getScheduler();

        scheduler.scheduleJob(jobDetail, simpleTrigger);

        scheduler.start();
    }
}
